!(function (e, t) {
  "object" == typeof exports && "object" == typeof module
    ? (module.exports = t())
    : "function" == typeof define && define.amd
    ? define([], t)
    : "object" == typeof exports
    ? (exports.webmessager = t())
    : (e.webmessager = t());
})(window, function () {
  return (function (e) {
    var t = {};
    function n(r) {
      if (t[r]) return t[r].exports;
      var i = (t[r] = { i: r, l: !1, exports: {} });
      return e[r].call(i.exports, i, i.exports, n), (i.l = !0), i.exports;
    }
    return (
      (n.m = e),
      (n.c = t),
      (n.d = function (e, t, r) {
        n.o(e, t) || Object.defineProperty(e, t, { enumerable: !0, get: r });
      }),
      (n.r = function (e) {
        "undefined" != typeof Symbol &&
          Symbol.toStringTag &&
          Object.defineProperty(e, Symbol.toStringTag, { value: "Module" }),
          Object.defineProperty(e, "__esModule", { value: !0 });
      }),
      (n.t = function (e, t) {
        if ((1 & t && (e = n(e)), 8 & t)) return e;
        if (4 & t && "object" == typeof e && e && e.__esModule) return e;
        var r = Object.create(null);
        if (
          (n.r(r),
          Object.defineProperty(r, "default", { enumerable: !0, value: e }),
          2 & t && "string" != typeof e)
        )
          for (var i in e)
            n.d(
              r,
              i,
              function (t) {
                return e[t];
              }.bind(null, i)
            );
        return r;
      }),
      (n.n = function (e) {
        var t =
          e && e.__esModule
            ? function () {
                return e.default;
              }
            : function () {
                return e;
              };
        return n.d(t, "a", t), t;
      }),
      (n.o = function (e, t) {
        return Object.prototype.hasOwnProperty.call(e, t);
      }),
      (n.p = ""),
      n((n.s = 7))
    );
  })([
    function (e, t, n) {
      "use strict";
      var r = (function (e) {
        function t(n, r, i) {
          !(function (e, t) {
            if (!(e instanceof t))
              throw new TypeError("Cannot call a class as a function");
          })(this, t),
            e.call(this, n),
            (this.listener = r),
            (this.context = i);
        }
        return (
          (function (e, t) {
            if ("function" != typeof t && null !== t)
              throw new TypeError(
                "Super expression must either be null or a function, not " +
                  typeof t
              );
            (e.prototype = Object.create(t && t.prototype, {
              constructor: {
                value: e,
                enumerable: !1,
                writable: !0,
                configurable: !0,
              },
            })),
              t &&
                (Object.setPrototypeOf
                  ? Object.setPrototypeOf(e, t)
                  : (e.__proto__ = t));
          })(t, e),
          t
        );
      })(n(4));
      e.exports = r;
    },
    function (e, t, n) {
      "use strict";
      e.exports = function (e, t, n, r, i, s, o, u) {
        if (!e) {
          var a;
          if (void 0 === t)
            a = new Error(
              "Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings."
            );
          else {
            var c = [n, r, i, s, o, u],
              p = 0;
            (a = new Error(
              t.replace(/%s/g, function () {
                return c[p++];
              })
            )).name = "Invariant Violation";
          }
          throw ((a.framesToPop = 1), a);
        }
      };
    },
    function (e, t, n) {
      var r = { EventEmitter: n(3), EmitterSubscription: n(0) };
      e.exports = r;
    },
    function (e, t, n) {
      "use strict";
      var r = n(0),
        i = n(5),
        s = n(6),
        o = n(1),
        u = (function () {
          function e() {
            !(function (e, t) {
              if (!(e instanceof t))
                throw new TypeError("Cannot call a class as a function");
            })(this, e),
              (this._subscriber = new i()),
              (this._currentSubscription = null);
          }
          return (
            (e.prototype.addListener = function (e, t, n) {
              return this._subscriber.addSubscription(
                e,
                new r(this._subscriber, t, n)
              );
            }),
            (e.prototype.once = function (e, t, n) {
              var r = this;
              return this.addListener(e, function () {
                r.removeCurrentListener(), t.apply(n, arguments);
              });
            }),
            (e.prototype.removeAllListeners = function (e) {
              this._subscriber.removeAllSubscriptions(e);
            }),
            (e.prototype.removeCurrentListener = function () {
              this._currentSubscription || o(!1),
                this._subscriber.removeSubscription(this._currentSubscription);
            }),
            (e.prototype.listeners = function (e) {
              var t = this._subscriber.getSubscriptionsForType(e);
              return t
                ? t.filter(s.thatReturnsTrue).map(function (e) {
                    return e.listener;
                  })
                : [];
            }),
            (e.prototype.emit = function (e) {
              var t = this._subscriber.getSubscriptionsForType(e);
              if (t) {
                for (var n = Object.keys(t), r = 0; r < n.length; r++) {
                  var i = n[r],
                    s = t[i];
                  s &&
                    ((this._currentSubscription = s),
                    this.__emitToSubscription.apply(
                      this,
                      [s].concat(Array.prototype.slice.call(arguments))
                    ));
                }
                this._currentSubscription = null;
              }
            }),
            (e.prototype.__emitToSubscription = function (e, t) {
              var n = Array.prototype.slice.call(arguments, 2);
              e.listener.apply(e.context, n);
            }),
            e
          );
        })();
      e.exports = u;
    },
    function (e, t, n) {
      "use strict";
      var r = (function () {
        function e(t) {
          !(function (e, t) {
            if (!(e instanceof t))
              throw new TypeError("Cannot call a class as a function");
          })(this, e),
            (this.subscriber = t);
        }
        return (
          (e.prototype.remove = function () {
            this.subscriber &&
              (this.subscriber.removeSubscription(this),
              (this.subscriber = null));
          }),
          e
        );
      })();
      e.exports = r;
    },
    function (e, t, n) {
      "use strict";
      var r = n(1),
        i = (function () {
          function e() {
            !(function (e, t) {
              if (!(e instanceof t))
                throw new TypeError("Cannot call a class as a function");
            })(this, e),
              (this._subscriptionsForType = {}),
              (this._currentSubscription = null);
          }
          return (
            (e.prototype.addSubscription = function (e, t) {
              t.subscriber !== this && r(!1),
                this._subscriptionsForType[e] ||
                  (this._subscriptionsForType[e] = []);
              var n = this._subscriptionsForType[e].length;
              return (
                this._subscriptionsForType[e].push(t),
                (t.eventType = e),
                (t.key = n),
                t
              );
            }),
            (e.prototype.removeAllSubscriptions = function (e) {
              void 0 === e
                ? (this._subscriptionsForType = {})
                : delete this._subscriptionsForType[e];
            }),
            (e.prototype.removeSubscription = function (e) {
              var t = e.eventType,
                n = e.key,
                r = this._subscriptionsForType[t];
              r && delete r[n];
            }),
            (e.prototype.getSubscriptionsForType = function (e) {
              return this._subscriptionsForType[e];
            }),
            e
          );
        })();
      e.exports = i;
    },
    function (e, t, n) {
      "use strict";
      function r(e) {
        return function () {
          return e;
        };
      }
      var i = function () {};
      (i.thatReturns = r),
        (i.thatReturnsFalse = r(!1)),
        (i.thatReturnsTrue = r(!0)),
        (i.thatReturnsNull = r(null)),
        (i.thatReturnsThis = function () {
          return this;
        }),
        (i.thatReturnsArgument = function (e) {
          return e;
        }),
        (e.exports = i);
    },
    function (e, t, n) {
      "use strict";
      n.r(t),
        n.d(t, "getMessager", function () {
          return g;
        });
      var r,
        i = n(2),
        s = new Uint8Array(16);
      function o() {
        if (
          !r &&
          !(r =
            ("undefined" != typeof crypto &&
              crypto.getRandomValues &&
              crypto.getRandomValues.bind(crypto)) ||
            ("undefined" != typeof msCrypto &&
              "function" == typeof msCrypto.getRandomValues &&
              msCrypto.getRandomValues.bind(msCrypto)))
        )
          throw new Error(
            "crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported"
          );
        return r(s);
      }
      var u = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
      for (
        var a = function (e) {
            return "string" == typeof e && u.test(e);
          },
          c = [],
          p = 0;
        p < 256;
        ++p
      )
        c.push((p + 256).toString(16).substr(1));
      var l,
        d,
        f = function (e) {
          var t =
              arguments.length > 1 && void 0 !== arguments[1]
                ? arguments[1]
                : 0,
            n = (
              c[e[t + 0]] +
              c[e[t + 1]] +
              c[e[t + 2]] +
              c[e[t + 3]] +
              "-" +
              c[e[t + 4]] +
              c[e[t + 5]] +
              "-" +
              c[e[t + 6]] +
              c[e[t + 7]] +
              "-" +
              c[e[t + 8]] +
              c[e[t + 9]] +
              "-" +
              c[e[t + 10]] +
              c[e[t + 11]] +
              c[e[t + 12]] +
              c[e[t + 13]] +
              c[e[t + 14]] +
              c[e[t + 15]]
            ).toLowerCase();
          if (!a(n)) throw TypeError("Stringified UUID is invalid");
          return n;
        },
        h = 0,
        y = 0;
      var b = function (e, t, n) {
          var r = (t && n) || 0,
            i = t || new Array(16),
            s = (e = e || {}).node || l,
            u = void 0 !== e.clockseq ? e.clockseq : d;
          if (null == s || null == u) {
            var a = e.random || (e.rng || o)();
            null == s && (s = l = [1 | a[0], a[1], a[2], a[3], a[4], a[5]]),
              null == u && (u = d = 16383 & ((a[6] << 8) | a[7]));
          }
          var c = void 0 !== e.msecs ? e.msecs : Date.now(),
            p = void 0 !== e.nsecs ? e.nsecs : y + 1,
            b = c - h + (p - y) / 1e4;
          if (
            (b < 0 && void 0 === e.clockseq && (u = (u + 1) & 16383),
            (b < 0 || c > h) && void 0 === e.nsecs && (p = 0),
            p >= 1e4)
          )
            throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");
          (h = c), (y = p), (d = u);
          var _ = (1e4 * (268435455 & (c += 122192928e5)) + p) % 4294967296;
          (i[r++] = (_ >>> 24) & 255),
            (i[r++] = (_ >>> 16) & 255),
            (i[r++] = (_ >>> 8) & 255),
            (i[r++] = 255 & _);
          var v = ((c / 4294967296) * 1e4) & 268435455;
          (i[r++] = (v >>> 8) & 255),
            (i[r++] = 255 & v),
            (i[r++] = ((v >>> 24) & 15) | 16),
            (i[r++] = (v >>> 16) & 255),
            (i[r++] = (u >>> 8) | 128),
            (i[r++] = 255 & u);
          for (var m = 0; m < 6; ++m) i[r + m] = s[m];
          return t || f(i);
        },
        _ = function (e, t, n, r) {
          return new (n || (n = Promise))(function (i, s) {
            function o(e) {
              try {
                a(r.next(e));
              } catch (e) {
                s(e);
              }
            }
            function u(e) {
              try {
                a(r.throw(e));
              } catch (e) {
                s(e);
              }
            }
            function a(e) {
              var t;
              e.done
                ? i(e.value)
                : ((t = e.value),
                  t instanceof n
                    ? t
                    : new n(function (e) {
                        e(t);
                      })).then(o, u);
            }
            a((r = r.apply(e, t || [])).next());
          });
        };
      function v(e) {
        return (
          Object.prototype.toString.call(e) ===
          Object.prototype.toString.call({})
        );
      }
      class m {
        constructor() {
          (this._emitter = new i.EventEmitter()),
            (this._webView = null),
            (this._listeners = []),
            (this._callbacks = {}),
            (this._handleMessage = e => {
              try {
                const t = e.nativeEvent ? e.nativeEvent.data : e.data,
                  n = JSON.parse(t);
                "response" === n.type
                  ? this._emitter.emit(n.id, n.payload)
                  : this._emitter.emit(n.action, n);
              } catch (e) {}
            }),
            this.addListener("__CALLBACK__", e => {
              const { id: t, params: n } = e,
                r = this._callbacks[t];
              r && r(...n);
            });
        }
        get messageHandler() {
          return this._handleMessage;
        }
        setWebView(e) {
          this._webView = e;
        }
        _stringifyPayload(e) {
          const t = e => {
            for (let n in e)
              if ("function" == typeof e[n]) {
                const t = b();
                (this._callbacks[t] = e[n]),
                  (e[n] = { __type__: "__CALLBACK__", id: t });
              } else v(e[n]) && (e[n] = t(e[n]));
            return e;
          };
          return e.map(e => (v(e) ? t(e) : e));
        }
        _parsePayload(e) {
          const t = e => {
            for (let n in e)
              if (
                e[n] &&
                e[n].hasOwnProperty("__type__") &&
                "__CALLBACK__" === e[n].__type__
              ) {
                const t = e[n].id;
                e[n] = (...e) => {
                  this.send("__CALLBACK__", [{ id: t, params: e }]);
                };
              } else v(e[n]) && (e[n] = t(e[n]));
            return e;
          };
          return e.map(e => (v(e) ? t(e) : e));
        }
        _removeCallback(e) {
          const t = e => {
            for (let n in e)
              if (
                e[n] &&
                e[n].hasOwnProperty("__type__") &&
                "__CALLBACK__" === e[n].__type__
              ) {
                const t = e[n].id;
                delete this._callbacks[t];
              } else v(e[n]) && t(e[n]);
          };
          e.forEach(e => {
            v(e) && t(e);
          });
        }
        send(e, t) {
          return new Promise((n, r) => {
            const i = b(),
              s = this._stringifyPayload(t);
            if (
              (this._emitter.once(i, (...e) => {
                this._removeCallback(s), n(e);
              }),
              this._webView)
            ) {
              const t = { id: i, action: e, payload: s, type: "request" };
              this._webView.postMessage(JSON.stringify(t));
            } else r("WebView is undefined");
          });
        }
        addListener(e, t) {
          const n = this._emitter.addListener(e, e =>
            _(this, void 0, void 0, function* () {
              var n;
              e.payload = this._parsePayload(e.payload);
              const r = yield t(...e.payload);
              if ("request" === e.type) {
                const t = {
                  id: e.id,
                  type: "response",
                  payload: r,
                  action: e.action,
                };
                null === (n = this._webView) ||
                  void 0 === n ||
                  n.postMessage(JSON.stringify(t));
              }
            })
          );
          return this._listeners.push(n), n;
        }
        removeListener(e, t) {
          this._emitter.listeners(e).forEach(e => {
            const t = this._listeners.find(t => t.listener == e);
            t && t.remove();
          }),
            t();
        }
        removeAllListeners(e) {
          this._emitter.removeAllListeners(e), (this._listeners = []);
        }
        listen(e = {}) {
          return Object.keys(e).map(t => this.addListener(t, e[t]));
        }
        isAvailable() {
          return !!this._webView;
        }
        requstPermission(e) {
          return this.send("requstPermission", [e]);
        }
        getCurrentLocation() {
          return this.send("getCurrentLocation", []);
        }
        visibleWebProgress(e) {
          return this.send("visibleWebProgress", [e]);
        }
        close() {
          return this.send("close", []);
        }
        setTitle(e) {
          return this.send("setTitle", [e]);
        }
        showLoading() {
          return this.send("showLoading", []);
        }
        hiddenLoading() {
          return this.send("hiddenLoading", []);
        }
        showToast(e) {
          return this.send("showToast", [e]);
        }
        showNavBar() {
          return this.send("showNavBar", []);
        }
        hideNavBar() {
          return this.send("hideNavBar", []);
        }
        toAPPPage(e) {
          return this.send("toAPPPage", [e]);
        }
        toAppPageByUrl(e) {
          return this.send("toAppPageByUrl", [e]);
        }
        openFile(e) {
          return this.send("openFile", [e]);
        }
        chooseFile(e) {
          return this.send("chooseFile", [e]);
        }
        logout() {
          return this.send("logout", []);
        }
        upgradeApp() {
          return this.send("upgradeApp", []);
        }
        openShare(e) {
          return this.send("openShare", [e]);
        }
      }
      let w = null;
      "undefined" != typeof window &&
        window.addEventListener &&
        ((w = new m()),
        window.ReactNativeWebView
          ? (w.setWebView(window.ReactNativeWebView),
            /android/i.test(navigator.userAgent)
              ? document.addEventListener("message", w.messageHandler)
              : window.addEventListener("message", w.messageHandler))
          : console.warn("window.ReactNativeWebView is undefined"));
      t.default = m;
      function g() {
        return w;
      }
    },
  ]);
});
